package com.yanqu.road.server.logic.activity.condition.horserun;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.horserun.HorseRunUserBaseData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseUserYRankCondition;
import com.yanqu.road.server.manger.activity.horserun.HorseRunMgr;

import java.math.BigInteger;

public class HorseRunPersonalGradeRankCondition extends BaseUserYRankCondition {
    public HorseRunPersonalGradeRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {

        HorseRunUserBaseData userBaseData = (HorseRunUserBaseData) object;
        if (userBaseData ==null){
            HorseRunMgr.getLogger().error("玩家小马快跑排行更新失败,活动id{},玩家id{}",baseActivityData.getActivityId(),baseActivityData.getPlayer().getUserId());
            return;
        }

        long grade = userBaseData.getActivityGrade();
        if (getValue().compareTo(BigInteger.valueOf(grade)) < 0) {
            setValue(BigInteger.valueOf(grade));
            setParam(userBaseData.getAppearanceString());
            rankChange();
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.HorseRunPersonalGradeRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.HorseRunPersonalGradeRank.getValue(), handle);
    }


}
